
/**加载客户分组管理页面*/
function loadCustomerGroup(){
    $.post(ctx+"myCustomer/loadCustomerGroup",{},function (r) {
        $("#myCustomer-modal").empty().append(r).modal('show');
    });
}

/**加载新增个人客户页面*/
function loadAddCustomer() {
    $.post(ctx+"PerSonCustomer/loadAddCustomer",{},function (r) {
        $("#myCustomer-modal").empty().append(r).modal('show');
    });
}

/**加载客户查重页面*/
function loadChecking(){
    $.post(ctx+"myCustomer/loadCkecking",{},function (r) {
        $("#myCustomer-check").empty().append(r).modal('show');
    });
}

/**加载客户详情页面*/
function viewMycusDetail(btn) {
    var type = $(btn).attr("data-type");
    var ids = $(btn).attr("data-id");
    $("#customer_uuid").val(ids);
    $("#customer_ids").val(ids);
    $("#customer_type").val(type);
    $.post(ctx+"myCustomer/loadCustomerDetail",{type:type},function (r) {
        $("#myCustomer-modal").empty().append(r).modal('show');
    });
}

/**加载我的重复客户*/
function selectMyselfDetail() {
    $.post(ctx+"myCustomer/loadCustomerDetail",{type:'4'},function (r) {
        $("#myself-modal").empty().modal("hide");
        $("#myCustomer-modal").empty().append(r).modal('show');
    });
}

/**创建分组名称*/
function addGroupName() {
    var name = $("#groupName").val();
    if(name==""){
        $JuXue.n_warning("请填写分组名称！");return;
    }
    var url = ctx+"myCustomer/addGroup";
    $.post(url,{"cGroupName":name},function (r) {
        if(r.code === 0){
            group_table_init();
            init_left_groupList();
            $("#groupName").val('');
            $JuXue.n_success(r.msg);
        }else{
            $JuXue.n_danger(r.msg);
        }
    });
}
/**选择分组**/
function selectGroup(btn) {
    var uuid= $(btn).attr("uuid");
    if (uuid !=undefined) $("#selectFroup").val(uuid);
    $("#loadTabId").val("mycus");
    $JuXue.refreshTable('myEmpTable');
}
/**综合查询搜索栏**/
function selectSearch(btn){
    $("#stype").text($(btn).text());
    var data_s = $(btn).attr("data");
    $("#searchType").val(data_s);
    $JuXue.refreshTable('myEmpTable');
}

/**选择时间类型**/
function selectMyTime(btn) {
    var data_cliak = $(btn).attr("data-click");
    if(data_cliak === "selft"){
        $("#select_time").removeClass("hidden");
        $("#starttime").val(moment().subtract("days",29).format("YYYY-MM-DD"));
        $("#endtime").val(moment().format("YYYY-MM-DD"));
    }else{
        $("#select_time").addClass("hidden");
        $("#starttime").val('')
        $("#endtime").val('');
    }
    $("#timeRemove").find("button").each(function () {
        $(this).removeClass("btn-primary");
    });
    $(btn).addClass("btn-primary");
    $JuXue.refreshTable('myEmpTable');
}
/**切换时间类型**/
function dynTime(btn) {
    var timeType = $(btn).attr("time");
    if (timeType!=undefined) $("#timeSelect").val(timeType);
   // $JuXue.refreshTable('myEmpTable');
}
/**选择通讯工具**/
function selectTool(btn) {
    $("#selectButton").find("button").each(function () {
        $(this).removeClass("btn-primary");
    });
    var dataId = $(btn).attr("data-id");
    var dataClick = $(btn).attr("data-click");
    if (dataId == ""){
        $("#selectTool").text("通讯工具筛选");
    }else if (dataId =="1") {
        if (dataClick == "1"){
            $("#selectTool").text("通讯工具: 有QQ");
        }else {
            $("#selectTool").text("通讯工具: 无QQ");
        }
    }else if(dataId =="2"){
        if (dataClick == "1"){
            $("#selectTool").text("通讯工具: 有邮箱");
        }else {
            $("#selectTool").text("通讯工具: 无邮箱");
        }
    } else if(dataId =="3"){
        if (dataClick == "1"){
            $("#selectTool").text("通讯工具: 有电话");
        }else {
            $("#selectTool").text("通讯工具: 无电话");
        }
    }
    $("#tongTool").val(dataClick);
    $("#typeTool").val(dataId);
    $(btn).addClass("btn-primary");
    $JuXue.refreshTable('myEmpTable');
}

/**选择有无销售计划**/
function selectSalePlan(btn) {
    $("#selectPlanButton").find("button").each(function () {
        $(this).removeClass("btn-primary");
    });
    var dataId = $(btn).attr("data-id");
    if (dataId == ""){
        $("#selectPaln").text("销售计划筛选");
    }else if (dataId =="1") {
        $("#selectPaln").text("销售计划: 有");
    }else if(dataId =="2"){
       $("#selectPaln").text("销售计划: 无");
    }
    $("#selectPlanId").val(dataId);
    $(btn).addClass("btn-primary");
    $JuXue.refreshTable('myEmpTable');
}
/**选择资源类型工具**/
function selectmySourType(btn) {
    $("#selecttypeButton").find("button").each(function () {
        $(this).removeClass("btn-primary");
    });
    var dataId = $(btn).attr("data-id");
    if (dataId == ""){
        $("#selecttype").text("资源类型筛选");
    }else if (dataId =="1") {
        $("#selecttype").text("资源类型: 推广资源");
    }else if(dataId =="2"){
      $("#selecttype").text("资源类型: 网校资源");
    }else if(dataId == "3"){
        $("#selecttype").text("资源类型: 大资源 ");
    }else if(dataId == "5"){
        $("#selecttype").text("资源类型: AI资源 ");
    }else {
        $("#selecttype").text("资源类型: 个人资源");
    }
    $("#SourType").val(dataId);
    $(btn).addClass("btn-primary");
    $JuXue.refreshTable('myEmpTable');
}
/**加载公司公海*/
function loadBigSea() {
    $(".theme-panel").removeClass("active");
    $("#selectTheme").hide();
    $("#loadTabId").val('allsea');
    controllMuenuStatus();
    $JuXue.refreshTable('myEmpTable');
}
/**添加销售计划*/
function addSalePlan(btn) {
    $("#saleplanTypehide").val($(btn).attr("data-click"));
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    if (!ids.length) {$JuXue.n_warning("请勾选需要分配的客户信息！");return;}
    $.post(ctx+"myCustomer/loadAddSalePlan",{},function(r){
        $("#myCustomer-modal").empty().append(r).modal('show');

        $.each(ids,function (index,val) {
            if (index > 3){
                $("#xialazhanshi").append("<button href=\"#\" onclick='$(this).remove()' uuid='"+val.uuid+"' types='"+val.types+"' class=\"btn btn-default p-3 m-4 \">"+val.nickname+"</button>");
            }else{
                $("#zhanshiButton").append("<button href=\"#\" onclick='$(this).remove()' uuid='"+val.uuid+"' types='"+val.types+"' class=\"btn btn-primary p-3 m-4 \">"+val.nickname+"</button>");
            }
        })
    });
}
/**加载部门公海*/
function loadDeptBigSea() {
    $(".theme-panel").removeClass("active");
    $("#selectTheme").hide();
    $("#loadTabId").val('deptsea');
    controllMuenuStatus();
    $JuXue.refreshTable('myEmpTable');
}
/**分享给我的*/
function shareTome() {
    $(".theme-panel").removeClass("active");
    $("#selectTheme").hide();
    $("#loadTabId").val('tome');
    controllMuenuStatus();
    $JuXue.refreshTable('myEmpTable');
}
/**我分享的*/
function meToShare() {
    $(".theme-panel").removeClass("active");
    $("#selectTheme").hide();
    $("#loadTabId").val('meto');
    controllMuenuStatus();
    $JuXue.refreshTable('myEmpTable');
}
/**加载选择人员界面*/
function loadShareCustomer() {
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    var ids_arr = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要分配的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].uuid;
        if (i !== (ids.length - 1)) ids_arr += ",";
    }
    $.post(ctx+"myCustomer/loadDistribute",{},function(r){
        $("#myCustomer-modal").empty().append(r).modal('show');
    });
}
/**放弃客户*/
function deleteCustomer() {
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    var ids_arr = "";
    var type_arr = "";
    var names = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要放弃的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        type_arr += ids[i].types;
        ids_arr  += ids[i].id;
        names += ids[i].nickname;
        if (i !== (ids.length - 1)){
            type_arr += ",";
            ids_arr += ",";
            names += ",";
        }
    }
    $JuXue.confirm({
        text: "确定放弃当前选择的客户？",
        confirmButtonText: "确定放弃"
    }, function() {
        $.post(ctx+"myCustomer/giveUpMyCus",{"keys":ids_arr,"types":type_arr,"names":names},function(r){
            if (r.code === 0) {
                $JuXue.n_success(r.msg);
                $JuXue.refreshTable("myEmpTable");
            } else {
                $JuXue.n_warning(r.msg);
            }
        });
    });
}
/**转让客户**/
function transferCustomer() {
    /**记录分配的数据id**/
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    if (!ids.length) {$JuXue.n_warning("请勾选需要转让的客户信息！");return;}
    $.post(ctx+"myCustomer/loadCustomertrancte",{},function (r) {$("#myCustomer-modal").empty().append(r).modal('show');});
}
/**部门公海领取客户**/
function receviceCustomer() {
    /**记录领取的数据id**/
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    var ids_arr = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要领取的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].id;
        if (i !== (ids.length - 1)) {ids_arr += ",";}
    }
    $.post(ctx+"myCustomer/reciverMyCustomer",{uuid:ids_arr},function (r) {
        if (r.code == 0){$JuXue.n_success("客户领取成功");
        }else{$JuXue.n_danger("客户已经被别人领取");}
        $JuXue.refreshTable("myEmpTable");
    });
}
/**公司公海领取客户**/
function gongsiReceviceCustomer() {
    /**记录领取的数据id**/
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    var ids_arr = "";var types = ""; /**类型**/
    if (!ids.length) {$JuXue.n_warning("请勾选需要领取的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {ids_arr += ids[i].id;types += ids[i].types;if (i !== (ids.length - 1)) {ids_arr += ",";types += ",";}}
    $.post(ctx+"myCustomer/companyMyCustomerLingqu",{uuid:ids_arr,"types":types},function (r) {
        if (r.code == 0){$JuXue.n_success(r.msg); $JuXue.refreshTable("myEmpTable");
        }else{$JuXue.n_danger(r.msg);}
    });
}
/**公司大公海 分配客户**/
function distributeCustomer() {
    /**记录分配的数据id**/
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    if (!ids.length) {$JuXue.n_warning("请勾选需要分配的客户信息！");return;}
    $.post(ctx+"myCustomer/loadAginDistribute",{},function (r) {
        $("#myCustomer-modal").empty().append(r).modal('show');
    });
}
/**设置标签**/
function setLabelforCustomer() {
    /**记录设置标签的数据id**/
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    if (!ids.length) {$JuXue.n_warning("请勾选需要标签的客户信息！");return;}
    $.post(ctx+"myCustomer/loadCustomerLabel",{},function (r) {
        $("#myCustomer-modal").empty().append(r).modal('show');
    });
}
/**移动分组**/
function addCustomerGroup(btn) {
    var groupuuid = $(btn).attr("uuid");
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    var ids_arr = "";
    var idss = ""; /**移动得id**/
    var types = ""; /**类型**/
    if (!ids.length) {$JuXue.n_warning("请勾选需要转让的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].uuid;
        idss += ids[i].id;
        types += ids[i].types;
        if (i !== (ids.length - 1)) {ids_arr += ",";idss += ",";types += ",";}
    }
    var url = ctx+"myCustomer/moveCusGroup";
    $.post(url,{"uuid":ids_arr,ids:idss,"types":types,groups:groupuuid},function (r) {
       if(r.code===0){
           $JuXue.n_success("操作成功");
       }else{
           $JuXue.n_success("操作失败，请联系网站管理员");
       }
    });
}
